#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright (c) 2015  Data Enlighten Technology (Beijing) Co.,Ltd

from mj_source.ford_web_source import FordWebSource
#from mj_source.landrover_web_source import LandRoverWebSource
from mj_source.gm_web_source import GMWebSource
from mj_source.partslink_source import PartLinkSourceWeb
from mj_source.bmw_web_source import BmwWebSource
import os


class SourceRegistry:
    crawler_registry = dict()

    @staticmethod
    def register(source_type, brand, source_class):
        key = SourceRegistry.create_key(source_type, brand)
        SourceRegistry.crawler_registry[key] = source_class

    @staticmethod
    def create_source(source_type, brand, root_dir):
        key = SourceRegistry.create_key(source_type, brand)
        source_class = SourceRegistry.crawler_registry.get(key, None)
        if source_class:
            return source_class(root_dir)
        return None

    @staticmethod
    def create_key(source_type, brand):
        return "{0}.{1}".format(source_type, brand)


if os.name == "nt":
    from .etk_source import AudiSourceETK
    SourceRegistry.register("ETK", "vwag", AudiSourceETK)

SourceRegistry.register("WEB", "vwag", PartLinkSourceWeb)
SourceRegistry.register("WEB", "ford", FordWebSource)
#SourceRegistry.register("WEB", "landrover", LandRoverWebSource)
SourceRegistry.register("WEB", "gm", GMWebSource)
SourceRegistry.register("WEB", "bmw", BmwWebSource)
#SourceRegistry.register("WEB", "psa", PsaWebSource)
#SourceRegistry.register("WEB", "kia", KIAWebSource)
